function managerReducer(state = [], action = { type: '', payload: null }) {
    let newstate = JSON.parse(JSON.stringify(state));

    if (action.type == 'ADD') {
        return newstate;
    } else if (action.type == 'DELETE') {
        let index = newstate.findIndex((element) => {
            return element.id == action.payload
        })
        if (index != -1) {
            newstate.splice(index, 1)
        }
        return newstate;
    } else if (action.type == 'EDIT') {
        let it = newstate.findIndex((item) => {
            return item.id == action.payload.id
        })
        if (it != -1) {
            newstate.splice(it, 1, action.payload)
        }

        return newstate;
    } else if (action.type == 'GET') {
        newstate = action.payload
        return newstate;
    } else if (action.type == 'FIND') {
        if (action.payload) {
            let searchlist = []
            newstate.filter((item) => {
                if ((item.name).includes(action.payload)) {
                    searchlist.push(item);
                    return;
                }
            })
            newstate = searchlist
        }
        return newstate;
    } else {
        return state
    }
}
//无名导出
export default managerReducer